<?php
/**
 * Created by PhpStorm.
 * User: chenx
 * Date: 18-3-13
 * Time: 下午9:05
 */

namespace backend\controllers;


use common\models\Ueditor;
use common\service\ConstantService;
use common\service\UeditorService;

class UeditorController extends BaseController
{
    public  $content = null;

    public function actionDemo(){
        $toolbars = UeditorService::getToolbars();
        return $this->renderPartial('demo',['toolbars'=>$toolbars]);
    }

    public function actionAdd(){
        if($this->isAjax() && $this->isPost()){
            global $content;
            $content = $this->post('content');
            $ueditor_model = new Ueditor();
            $ueditor_model->setAttributes(['content'=>$content]);
            if($ueditor_model->save()){
                return $this->renderJson([],'成功',ConstantService::$response_success);
            }else{
                return $this->renderJson([],'错误',ConstantService::$response_fail);

            }
        }
        return $this->renderPartial('demo');

    }

    public function actionModify(){
        $content = Ueditor::find()->where(['id'=>1])->asArray()->one();
        return $this->renderPartial('modify',['content'=>$content['content']]);
    }

}